// 端口号3010
const dbConfig = require("../config/dbConfig");

module.exports = {
  //用户购买记录所有数据
  buyhistory(req, res) {
    let {} = req.body;
    const sql = "select * from goumai";
    const arr = [];
    dbConfig.db(res, sql, arr, function (data) {
      res.send({
        code: 200,
        data: data,
      });
    });
  },
  //用户购买记录查询接口
  buyhistory2(req, res) {
    let { userid, iphone, quyu, qudao } = req.body.a;
    //const sql = 'SELECT * FROM goumai WHERE userid LIKE "%??%" OR iphone LIKE "%??%" OR quyu LIKE "%??%" OR qudao LIKE "%??%"';
    const sql = `SELECT * FROM goumai WHERE userid LIKE '%${userid}%' AND iphone LIKE '%${iphone}%' AND quyu LIKE '%${quyu}%' AND qudao LIKE '%${qudao}%'`;
    //const arr = [userid,iphone,quyu,qudao];
    dbConfig.db(res, sql, [], function (data) {
      res.send({
        code: 200,
        data: data,
      });
    });
  },
  buyhistory3(req, res) {
    let {} = req.body;
    const sql = "INSERT INTO goumai (userid, goumaishij, iphone,quyu,huode,qudao,jia,keyong) VALUES ('123',CURDATE(),'','单人明区',CURDATE(),'微信','28','可用')";
    const arr = [];
    dbConfig.db(res, sql, arr, function (data) {
      res.send({
        code: 200,
        data: data,
      });
    });
  },
};
